import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

/**
 * @description: 生成一组顺序数组并打乱输出
 * @author: WangBlue
 * @create: 2023-10-27 20:48
 **/
public class Shuffle {

    /**
     * 生成数组,
     * @return 生成好的数组
     */
    public static int [] myArray(){

        int[] array = new int[10];
        for (int i = 0; i < array.length; i++) {
            array[i] = i+1;
        }
        return array;
    }

    /**
     * 将数组打乱并输出
     * @return: 将数组打乱
     */
    public static void suffer(int[] array){
        if (array.length != 0) {
            // 随机定位下标j与i进行交换
            for (int i = 0; i <array.length ; i++) {
                int j = new Random().nextInt(array.length);
                int t = array[i];
                array[i] = array[j];
                array[j] = t;
            }

        }

    }

    public static void main(String[] args) {
        int[] ints = myArray();
        if (ints.length !=  0) {
            for (int i = 0; i <ints.length ; i++) {
                System.out.println("没有打乱之前的数组为: " + ints[i]);
            }
            System.out.println("接下来是打乱之后的数组=========================");
            suffer(ints);
            System.out.println("打乱之后的数组为：" + Arrays.toString(ints));

        }


    }

}
